<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019-01-31
 * Time: 14:32
 */

namespace app\index\controller;


use app\common\controller\HomeBase;
use app\common\model\Messagem;

class Message extends HomeBase
{

    /**
     * 前端 用户消息列表
     */
    public function messagelist($page = 1)
    {
        $params = input();
        if(array_key_exists("uid",$params) && $params['uid'] != ''){
            $list = Messagem::getListByUid($params['uid'], $page);
            if (sizeof($list) == 0) {
                return json(['code' => 300, 'msg' => '暂无数据']);
            }
            return json(['code' => 200, 'msg' => $list]);

        } else {
            return json(['code' => 300, 'msg' => '您还没有登录，请先登录。']);
        }
    }

    /**
     * 前端用户删除消息
     */
    public function delmessage()
    {
        $params = input();
        $validate_result = $this->validate($params, 'Wmessage');
        if ($validate_result !== true) {
            return  json(['code' => 300, 'msg' => $validate_result]);
        }
        $status =  Messagem::delMesById($params);
        if (!$status) {
            return  json(['code' => 300, 'msg' => '删除失败']);
        }
        return  json(['code' => 200, 'msg' => '删除成功']);
    }
}